package com.hfkh.keyun.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket backendDocket(){
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())  //配置API信息
                .groupName("管理端")   //配置分组
                .enable(true)    //是否开启swagger接口文档
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hfkh.keyun.controller.backend"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket frontendDocket(){
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())  //配置API信息
                .groupName("小程序端")   //配置分组
                .enable(true)    //是否开启swagger接口文档
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hfkh.keyun.controller.frontend"))
                .paths(PathSelectors.any())
                .build();
    }
    /**
     * 定义Api接口信息，例如：标题，描述，服务条款，版本号等
     */
    private ApiInfo apiInfo(){
      return   new ApiInfoBuilder()
                .title("科云视频库接口文档")//配置接口文档标题
                .description("科云视频库在线接口文档")  //设置接口文档描述
                .contact(new Contact("ww","http://localhost:8080/","2583301397@qq.com"))
                .termsOfServiceUrl("http://localhost:8080/swagger-ui/index.html")//设置服务条款Url
                .version("1.0.0")
                .build();
    }

}
